// index.js
var app = getApp()

Page({
  data: {

  },
  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '热马品牌商城小程序',
      path: '/pages/index/index',
      imageUrl: "/pages/images/logo.png",
      success: function (res) {
        // 转发成功
        wx.showToast({
          title: '转发成功！',
          icon: 'success',
          duration: 2000
        })
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
  onLoad: function (options) {
    var thiz = this
    var domainImg = app.globalData.domainImg
    var c_id = options.company_id
    var PageInterface = app.globalData.domain + app.globalData.PageInterface
    var domain = app.globalData.domain
    wx.getSystemInfo({
      success: function (res) {
        thiz.setData({
          domain: domain,
          hiddenLoading: false,
          windowHeight: res.windowHeight,
          windowWidth: res.windowWidth
        });
      }
    })

    //首页轮播图
    wx.request({
      url: PageInterface,
      method: 'POST',
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      data: {
        format_type: 'json',
        api_cate: 'Banner',
        api: 1001,
        c_id: c_id,
      },
      success: function (res) {
        if (res.data.data.length > 0) {
          res.data.data.forEach(function (element, index) {
            element.img_url = domain + element.img_url
          })
          thiz.setData({
            banners: res.data.data
          })
        }
      }
    });
    //导购视频
    wx.request({
      url: PageInterface,
      method: 'POST',
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      data: {
        format_type: 'json',
        api_cate: 'Curr',
        api: 3001,
        c_id: c_id,
      },
      success: function (res) {
        if (res.data.data.length > 0) {
          res.data.data.forEach(function (element, index) {
            element.curr_img = domain + element.curr_img
          })
          thiz.setData({
            zhibos: res.data.data
          })
        }
      }
    });
    //商品推荐
    wx.request({
      url: PageInterface,
      method: 'POST',
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      data: {
        format_type: 'json',
        api_cate: 'Goods',
        api: 4001,
        c_id: c_id,
      },
      success: function (res) {
        if (res.data.data.length > 0) {
          res.data.data.forEach(function (element, index) {
            element.default_img = domain + element.default_img
          })
          thiz.setData({
            shangpins: res.data.data
          })
        }
      }
    });
    //新闻资讯
    wx.request({
      url: PageInterface,
      method: 'POST',
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      data: {
        format_type: 'json',
        api_cate: 'News',
        api: 2001,
        c_id: c_id,
      },
      success: function (res) {
        if (res.data.data.length > 0) {
          res.data.data.forEach(function (element, index) {
            element.news_img = domain + element.news_img
          })
          thiz.setData({
            xinwen: res.data.data
          })
        }
      }
    });
    //企业信息
    wx.request({
      url: PageInterface,
      method: 'POST',
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      data: {
        format_type: 'json',
        api_cate: 'Company',
        api: 6003,
        c_id: c_id,
      },
      success: function (res) {
        res.data.data.company_logo = domain + res.data.data.company_logo
        thiz.setData({
          company: res.data.data,
          hiddenLoading: true
        })
      }
    });
  }
})